<template>
	<view class="user">
		<view class="top">
			<image src="../../static/images/history.png" mode="aspectFill"></image>
			<text class="text">浏览历史</text>
		</view>
		<view class="content">
			<NewsItem :item="item" @click.native="goDetail(item)" v-for="(item,index) in historyData" :key="item.id"></NewsItem>
		</view>
		<view class="noHistory" v-if="!historyData.length">
			<image src="../../static/images/nohis.png" mode="widthFix"></image>
			<view class="text">暂无浏览记录</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				historyData:[],
			};
		},
		// 每次进入页面都调用一次
		// 不用onLoad，因为只有第一次加载的时候才有
		onShow(){
			this.getData();
		},
		methods:{
			goDetail(item){
				uni.navigateTo({
					url:`../detail/detail?cid=${item.classid}&id=${item.id}`
				})
			},
			// 获取缓存浏览记录
			getData(){
				this.historyData = uni.getStorageSync('historyArr') || [];
			}
		}
	}
</script>

<style lang="scss" scoped>
.top{
	padding: 50rpx 0;
	background-color: #F8F8F8;
	color: #555;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	image{
		width: 150rpx;
		height: 150rpx;
	}
	.text{
		font-size: 38rpx;
		padding-top: 10rpx;
	}
}

.noHistory{
	display: flex;
	flex-direction: column;
	align-items: center;
	image{
		width: 450rpx;
	}
	text{
		font-size: 26rpx;
		color:#888;
	}
}
</style>
